/*
 * MCAL_SPI.c
 *
 *  Created on: Oct 16, 2025
 *      Author: ADMIN
 */

#include "MCAL_SPI.h"

SPI_ID_Type SPI_ID_0x01;


Std_ReturnType MCAL_SPI_Init(void)
{
    SPI_Creat(&Flash_SPI_Type , &hspi1);

    return E_OK;
}

Std_ReturnType MCAL_SPI_DeInit(void)
{
    HAL_SPI_MspDeInit(Flash_SPI_Type.spiHandle);

    return E_OK;
}

Std_ReturnType SPI_SendByteDate(SPI_ID_Type* spi_num)
{
    HAL_SPI_Transmit(spi_num->spiHandle,(uint8*)&spi_num->SendByteArr,1,1000);

    return E_OK;
}


Std_ReturnType SPI_SendDate(SPI_ID_Type* spi_num)
{
    if (spi_num->SendDateIndex != NULL)
    {
        HAL_SPI_Transmit(spi_num->spiHandle,(uint8*)spi_num->SendDateIndex,spi_num->SendDateLen,1000);
        return E_OK;
    }
    else
    {
        return E_NOT_OK;
    }  
}

Std_ReturnType SPI_ReceiveByteDate(SPI_ID_Type* spi_num)
{
    HAL_SPI_Receive(spi_num->spiHandle,&spi_num->ReceiveByteArr,1,1000);

    return E_NOT_OK;
}

Std_ReturnType SPI_ReceiveDate(SPI_ID_Type* spi_num)
{
    HAL_SPI_Receive(spi_num->spiHandle,spi_num->ReceiveDateIndex,spi_num->ReceiveDateLen,1000);
   
    return E_NOT_OK; 
}



void SPI_Creat(SPI_ID_Type* spi_num, SPI_HandleTypeDef* spiHandle)
{
    /* SW information */
    spi_num->spiHandle = spiHandle;

    /* Send configure information */
    spi_num->SendByteArr = 0;
    spi_num->SendDateIndex = NULL;
    spi_num->SendDateLen = 0;

    /* Receive configure information */
    spi_num->ReceiveByteArr = 0;
    spi_num->ReceiveDateIndex = NULL;
    spi_num->ReceiveDateCnt = 0;
    spi_num->ReceiveDateLen = 0;

    /* Function Index */
    spi_num->SPISendByte_Func = SPI_SendByteDate;
    spi_num->SPISendDate_Func = SPI_SendDate;
    spi_num->SPIReceiveByte_Func = SPI_ReceiveByteDate;
    spi_num->SPIReceiveDate_Func = SPI_ReceiveDate;

}